<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'pnm-form',
	'enableAjaxValidation'=>true,
	'htmlOptions'=>array('enctype' => 'multipart/form-data'),
));
?>

	<p class="note">
		Fields with <span class="required">*</span> are required.
	</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
	<?php echo $form->labelEx($model,'first_name'); ?>
	<?php echo $form->textField($model,'first_name',array('size'=>32,'maxlength'=>32)); ?>
	<?php echo $form->error($model,'first_name'); ?>
	</div>

	<div class="row">
	<?php echo $form->labelEx($model,'last_name'); ?>
	<?php echo $form->textField($model,'last_name',array('size'=>32,'maxlength'=>32)); ?>
	<?php echo $form->error($model,'last_name'); ?>
	</div>

	<div class="row">
	<?php echo $form->labelEx($model,'picture_id'); ?>
	<?php echo $form->fileField($model,'picture_id'); ?>
	<?php if (!$model->isNewRecord): ?>
		<p class="note">Leave blank to keep current picture</p>
		<?php endif; ?>
		<?php echo $form->error($model,'picture_id'); ?>
	</div>

	<div class="row">
	<?php echo $form->labelEx($model,'phone_number'); ?>
	<?php echo $form->textField($model,'phone_number',array('size'=>60,'maxlength'=>64)); ?>
	<?php echo $form->error($model,'phone_number'); ?>
	</div>
	
	<div class="row">
	<?php echo $form->labelEx($model,'email'); ?>
	<?php echo $form->textField($model,'email',array('size'=>60,'maxlength'=>64)); ?>
	<?php echo $form->error($model,'email'); ?>
	</div>	

	<div class="row">
	<?php echo $form->labelEx($model,'major'); ?>
	<?php echo $form->textField($model,'major',array('size'=>60,'maxlength'=>64)); ?>
	<?php echo $form->error($model,'major'); ?>
	</div>

	<div class="row">
	<?php echo $form->labelEx($model, 'dorm'); ?>
	<?php echo $form->textField($model, 'dorm', array('size'=>60,'maxlength'=>64)); ?>
	<?php echo $form->error($model, 'dorm'); ?>
	</div>
	
<?php

foreach ($customFields as $field) {
    echo '<div class="row">';
    echo CHtml::label($field->label, 'CustomField[' . $field->id . ']');

    $htmlopts = array();
    if (!empty($field->field_attributes)) {
        $temp = str_getcsv($field->field_attributes);
        array_walk($temp, create_function('&$val', '$val = trim($val);'));
        for ($i = 0; $i < count($temp); $i += 2) {
            $htmlopts[$temp[$i]] = $temp[$i+1];
        }    
    }    
    $default = "";
    if (!$model->isNewRecord) { //If we are updating PNM, we should populate form
        foreach ($customFieldValues as $customFieldValue) {
            if ($customFieldValue->custom_field_id == $field->id) {
                $default = $customFieldValue->value;
            }
        }
    }
    
    if ($field->field_type == "Text Box") {
        echo CHtml::textField('CustomField[' . $field->id . ']', $default, $htmlopts);
    } else if ($field->field_type == "Text Area") {
        echo CHtml::textArea('CustomField[' . $field->id . ']', $default, $htmlopts);
    } else if ($field->field_type == "Drop Down") {
        echo CHtml::dropDownList('CustomField[' . $field->id . ']', $default, $htmlopts);
    }
    echo '</div>';
}

?>	

	<div class="row buttons">
	<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

	<?php $this->endWidget(); ?>
</div>
<!-- form -->
